#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "CPushButton.h"
#include <QPushButton>
#include <QVBoxLayout>
#include <QBoxLayOut>
#include <QFrame>
#include <QStackedWidget>
#include <QSpacerItem>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 向布局中添加按钮
    CPushButton *button1 = new CPushButton("Button 1", ui->sideBar);
    button1->setIcon(QIcon(":/icons/permission.png"));
    //button1->resize(40, 100);
    CPushButton *button2 = new CPushButton("Button 2", ui->sideBar);
    button2->setIcon(QIcon(":/icons/settings.png"));

    CPushButton *button3 = new CPushButton("Button 3", ui->sideBar);
    button3->setIcon(QIcon(":/icons/settings.png"));

    //CPushButton *button4 = new CPushButton("Button 4", ui->sideBar);
    //button4->setIcon(QIcon(":/icons/user.png"));

    QSpacerItem *verticalSpacer = new QSpacerItem(0, QSizePolicy::MinimumExpanding);


    ui->sideBar->layout()->addWidget(button1);
    ui->sideBar->layout()->addWidget(button2);
    ui->sideBar->layout()->addWidget(button3);
    //ui->sideBar->layout()->addWidget(button4);

    verticalSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);

    ui->sideBar->layout()->addItem(verticalSpacer);

    //ui->sideBar->layout()->addItem(verticalSpacer); // 假设yourLayout是一个指向QVBoxLayout的指针


     //设置中心小部件为 QMainWindow 的中心部件
  //   setCentralWidget(centralWidget);
//}
    ui->stackedWidget->addWidget(&userWnd);
    ui->stackedWidget->addWidget(&permissionWnd);
    ui->stackedWidget->addWidget(&settingsWnd);

    btnGroup.setExclusive(false);
    btnGroup.addButton(button1, 0);
    btnGroup.addButton(button2, 1);
    btnGroup.addButton(button3, 2);
    connect(&btnGroup, QOverload<int>::of(&QButtonGroup::buttonClicked), ui->stackedWidget, &QStackedWidget::setCurrentIndex);

    // 设置默认选中的页面
    btnGroup.button(0)->setChecked(true);
    ui->stackedWidget->setCurrentIndex(0);
}

MainWindow::~MainWindow()
{
    delete ui;
}
